
'''	
	This file is part of Roseena.
	
	Copyright (C) 2008	Mohamed Hazem <mohamed.hazem@student.guc.edu.eg>
	Copyright (C) 2008	Mostafa Hany <mostafa.hany@student.guc.edu.eg>

	
	Roseena is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Roseena is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Roseena.	If not, see <http://www.gnu.org/licenses/>.
'''

from PyQt4.QtCore import SIGNAL, SLOT
from PyQt4.QtNetwork import QTcpServer
from ProxySocketThread import proxySocketThread


class ProxyServer(QTcpServer):
	'''
	The Server class responsible for handling incoming connections.
	'''

	def __init__(self, host, port, parent=None):
		'''
		Server's __init__ method; takes two arguments: QHostAddress host
		and int port ... where host is the address to listen to incoming connections from.
		'''
		QTcpServer.__init__(self, parent)

		self.listen(host, port)

	def incomingConnection(self, socketId):
		proxySocket = proxySocketThread(socketId, self)
		self.connect(proxySocket, SIGNAL("finished()"), proxySocket, SLOT("deleteLater()"))
		proxySocket.start()
